home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / Animation Wizard.dir / 00004_IncrDecrValue.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  3.5 KB  |  122 lines

  1. property iType, iMin, iMax, iInc, ichField, ichButton, iLastValidValue, iFieldName, iCastNumNormal, iCastNumIncr, iCastNumDecr
  2.  
  3. on birth me, type, min, max, incAmount, chText, theFieldName
  4.   set iType to type
  5.   set iMin to min
  6.   set iMax to max
  7.   set iInc to incAmount
  8.   set ichField to chText
  9.   set ichButton to ichField + 1
  10.   set iLastValidValue to iMin
  11.   set iFieldName to theFieldName
  12.   mSetValue(me, iLastValidValue)
  13.   return me
  14. end
  15.  
  16. on mHit me
  17.   set castNumNormal to the castNum of sprite ichButton
  18.   set iCastNumNormal to castNumNormal
  19.   set iCastNumIncr to castNumNormal + 1
  20.   set iCastNumDecr to castNumNormal + 2
  21.   set iLastValidValue to field the castNum of sprite ichField
  22.   set lowerLimitBeepedFlag to 0
  23.   set upperLimitBeepedFlag to 0
  24.   set mouseDownFlag to 1
  25.   set firstTimeFlag to 1
  26.   repeat while mouseDownFlag
  27.     if rollOver(ichButton) then
  28.       set okToChangeValueFlag to 1
  29.       if the mouseV <= the locV of sprite ichButton then
  30.         set lowerLimitBeepedFlag to 0
  31.         set sign to 1
  32.         if iLastValidValue = iMax then
  33.           set okToChangeValueFlag to 0
  34.           if not upperLimitBeepedFlag then
  35.             beep()
  36.             set upperLimitBeepedFlag to 1
  37.             set the castNum of sprite ichButton to castNumNormal
  38.             updateStage()
  39.           end if
  40.         end if
  41.       else
  42.         set upperLimitBeepedFlag to 0
  43.         set sign to -1
  44.         if iLastValidValue = iMin then
  45.           set okToChangeValueFlag to 0
  46.           if not lowerLimitBeepedFlag then
  47.             beep()
  48.             set lowerLimitBeepedFlag to 1
  49.             set the castNum of sprite ichButton to castNumNormal
  50.             updateStage()
  51.           end if
  52.         end if
  53.       end if
  54.       if okToChangeValueFlag then
  55.         mChangeValue(me, sign)
  56.       end if
  57.     else
  58.       set the castNum of sprite ichButton to castNumNormal
  59.       updateStage()
  60.     end if
  61.     if firstTimeFlag then
  62.       set firstTimeFlag to 0
  63.       wait(15)
  64.     end if
  65.     set mouseDownFlag to the mouseDown
  66.   end repeat
  67.   set the castNum of sprite ichButton to castNumNormal
  68.   updateStage()
  69. end
  70.  
  71. on mChangeValue me, sign
  72.   if sign = 1 then
  73.     set the castNum of sprite ichButton to iCastNumIncr
  74.   else
  75.     set the castNum of sprite ichButton to iCastNumDecr
  76.   end if
  77.   updateStage()
  78.   if iType = #int then
  79.     set iLastValidValue to (integer(iLastValidValue / iInc) * iInc) + (iInc * sign)
  80.   else
  81.     if iType = #real then
  82.       set iLastValidValue to (iLastValidValue / iInc * iInc) + (iInc * sign)
  83.     end if
  84.   end if
  85.   put iLastValidValue into field the castNum of sprite ichField
  86. end
  87.  
  88. on mGetValue me
  89.   set theTypedInString to the text of field iFieldName
  90.   set newValue to value(theTypedInString)
  91.   if iLastValidValue <> newValue then
  92.     set iLastValidValue to newValue
  93.   end if
  94.   return iLastValidValue
  95. end
  96.  
  97. on mSetValue me, theNewValue
  98.   if (theNewValue < iMin) or (theNewValue > iMax) then
  99.     alert("Bad value passed to IncrDecrValue:" && theNewValue)
  100.     return 
  101.   end if
  102.   set iLastValidValue to theNewValue
  103.   set the text of field iFieldName to string(iLastValidValue)
  104.   updateStage()
  105. end
  106.  
  107. on mValidate me
  108.   set theTypedInString to the text of field iFieldName
  109.   set newValue to value(theTypedInString)
  110.   if voidp(newValue) then
  111.     alert("The value in the " & iFieldName & " field must be numeric")
  112.     mSetValue(me, iMin)
  113.     return 0
  114.   end if
  115.   if (newValue > iMax) or (newValue < iMin) then
  116.     alert("Please enter a value between " & iMin & " and " & iMax & " into the " & iFieldName & " field.")
  117.     mSetValue(me, iMin)
  118.     return 0
  119.   end if
  120.   return 1
  121. end
  122.